package logic

import (
	"context"
	"user-reg-hub/models/mysql"

	"user-reg-hub/userrpc/internal/svc"
	"user-reg-hub/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailLogic {
	return &UserDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户详情
func (l *UserDetailLogic) UserDetail(in *userrpc.UserDetailRequest) (*userrpc.UserDetailResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User
	if err := user.UserDetail(mysql.DB, in.UserId); err != nil {
		return nil, err
	}

	return &userrpc.UserDetailResponse{
		Account:  user.Account,
		Password: user.Password,
		UserId:   int64(user.ID),
	}, nil
}
